<template>
  <section>
    <!--<el-button size="mini" @click="addReportBtn">新建报告</el-button>-->
    <el-table :data="reports">
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column prop="title" label="标题"></el-table-column>
      <el-table-column prop="customerName" label="用户"></el-table-column>
      <el-table-column prop="state" label="状态">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="throughPDF(scope.row)"  v-if="scope.row.data.jobId">预览</el-button>
          <el-button size="mini" type="primary" @click="confirmBtn(scope.row)" v-if="scope.row.state !==2">就绪报告</el-button>
        </template>
      </el-table-column>
    </el-table>
  </section>
</template>

<script>
  import DateFormat from '@/common/date-formater'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  import errHandler from '@/assets/errHandler.js'
  export default {
    name: "reportDataList",
    props:['reportList'],
    data() {
      return {
        reportDataList:null,
        reports:null,
        totalPage:0,
        selReportData:false,
      }
    },
    computed:{
    },
    created() {
      console.log(this.reportList)
      this.getReportList()
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getReportList(pageNo){
        this.fetch({name:"getReportList",data:{page:pageNo?pageNo:0}})
          .then(res=>{
            if(this.reportList){
              console.log('job过来的')
              this.reports=this.reportList
              return
            }
            this.reports=res.content
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      confirmBtn(row){
        console.log(row)
        this.$emit('done',row.id)
      },
      throughPDF(row){
        console.log(row)
        console.log('在线浏览')
        this.throughReportPDFOnline(row)
      },
      throughReportPDFOnline(row){
        this.fetch({name:"throughReportPDFOnline",
          data:{expirationTime:5,
            bucketName:row.data.bucketName,
            key:row.data.reportUrl,
            responseContentType:"application/pdf",
            responseContentDispositon:'inline;fileName=XXX.pdf',
          }})
          .then(res=>{
            console.log(res)
            window.open(res,'_blank')
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      }
    }
  }
</script>

<style scoped>

</style>
